const { app, BrowserWindow } = require("electron");
const path = require("node:path");

// 屏蔽安全警告
// ectron Security Warning (Insecure Content-Security-Policy)
process.env["ELECTRON_DISABLE_SECURITY_WARNINGS"] = "true";

const createWindow = () => {
  const win = new BrowserWindow({
    // 窗口图标
    icon: path.join(__dirname, "resource/shortcut.ico"),
    fullscreen: true,
    // frame: false,
    transparent: true,
    backgroundColor: "#00000000",
    webPreferences: {
      //contextIsolation: false, // allow use with Electron 12+
      nodeIntegration: true,
      preload: path.join(__dirname, "./src/preload.js"),
    },
  });
  win.setMenu(null);

  // development模式
  if (process.env.VITE_DEV_SERVER_URL) {
    win.loadURL(process.env.VITE_DEV_SERVER_URL);
    // 开启调试台
    win.webContents.openDevTools();
  } else {
    win.loadFile(path.join(__dirname, "../dist/index.html"));
  }
};

app.whenReady().then(() => {
  createWindow();
  app.on("activate", () => {
    if (BrowserWindow.getAllWindows().length === 0) createWindow();
  });
});

app.on("window-all-closed", () => {
  if (process.platform !== "darwin") app.quit();
});
